// 食物类
class Food {
    // 食物对应的dom元素
    element: HTMLElement;
    constructor() {
        this.element = document.getElementsByClassName('food')[0] as HTMLElement;
    }

    // dom元素对应的x、y的相对坐标
    get X() {
        return this.element.offsetLeft;
    }

    get Y() {
        return this.element.offsetTop;
    }

    // 更改食物的坐标，只能是0-290，且只能被10整除的坐标
    change() {
        const left = Math.round(Math.random() * 29) * 10;
        const top = Math.round(Math.random() * 29) * 10;
        this.element.style.left = left + 'px';
        this.element.style.top = top + 'px';
    }
}


// const food = new Food();
// console.log(food.X, food.Y);
// food.change()

export default Food;